<?php 

print_r($_GET);
print_r($_POST);
 

if(isset($_POST['keyword'])){
	$sqlObj = new mysqlClass();
	$params=array();
	$params['keyword']=$_POST['keyword'];

	$params['language_id']=1;
	$params['text'] = $_POST['translate_EN'];
	$sqlObj->insert('translates',$params);
	// $sqlObj->insert('translates_dan',$params);

	$params['language_id']=2;
	$params['text'] = $_POST['translate_RO'];
	$sqlObj->insert('translates',$params);
	// $sqlObj->insert('translates_dan',$params);

	$params['language_id']=3;
	$params['text'] = $_POST['translate_DE'];
	$sqlObj->insert('translates',$params);
	// $sqlObj->insert('translates_dan',$params);

	$params['language_id']=4;
	$params['text'] = $_POST['translate_FR'];
	$sqlObj->insert('translates',$params);
	// $sqlObj->insert('translates_dan',$params);

	$params['language_id']=5;
	$params['text'] = $_POST['translate_ES'];
	$sqlObj->insert('translates',$params);
	// $sqlObj->insert('translates_dan',$params);
	echo "<span>Word translated</span>";
}else
if(isset($_POST['word_post'])){
	// print_r($_POST);
	// print_r($_SESSION);	
			// echo "<pre>";
			// print_r($user);
			// echo "</pre>";
	// $sql = mysql_query("INSERT INTO ");
	$params=array();
	$params['lang_id']=2;
	$params['keyword']=$_POST['word_post'];
	$params['text']=$_POST['translate'];
	print_r($params);
	$userObj->insert('translates',$params);
	echo "<span>Word translated</span>";
}else{
	?>
	<script>
	function save_translate(){
		$("#translate_form").submit();		
	}
	</script>
	<form class="form-horizontal" id='translate_form' method = 'post' action=''>
		<?php if(isset($_GET['word'])){ ?>
		<div class="control-group">
			<span>Translate word "<?php echo $_GET['word']; ?>"</span><br />
			<label class="control-label" for="translate">Translate:</label>
			<div class="controls">
				<input id="translate" name='translate' type="text" placeholder="traducere"/>
				<input type="hidden" value='<?php echo $_GET['word']; ?>' name='word_post'/>
			</div>
		</div>
		<div class="form-actions">
			<button id='submit_form' class="btn btn-info" type="button" onclick='save_translate();'>
				<i class="icon-ok bigger-110"></i>
				Save
			</button>
		</div>
		<?php }else if(isset($_GET['keyword'])){ ?>
		<span>Translate word "<?php echo $_GET['keyword']; ?>"</span><br />
		<?php
		
		$sqlObj = new mysqlClass();

		$lang = $sqlObj->fetch_table('languages');
		
		foreach($lang as  $value){ ?>
		<div class="control-group">		
			<label class="control-label" for="translate">Translate <?php echo $value['abv'] ?>:</label>
			<div class="controls">
				<input id="translate_<?php echo  $value['abv'] ?>" name='translate_<?php echo $value['abv'] ?>' type="text" placeholder="traducere"/>

			</div>
		</div>
		<?php }

		?>
		<input type="hidden" value='<?php echo $_GET['keyword']; ?>' name='keyword'/>
		<div class="form-actions">
			<button id='submit_form' class="btn btn-info" type="button" onclick='save_translate();'>
				<i class="icon-ok bigger-110"></i>
				Save
			</button>
		</div>
		<?php } ?>
	</form>
	<?php } ?>